package com.droidclaimcustomer.activity;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.List;

import com.droidclaimcustomer.dto.ClaimInfoForCustomerResultBlDto;
import com.droidclaimcustomer.model.ClaimInfoModel;
import com.droidclaimcustomer.model.ClaimHistoryModel;
import com.droidclaimcustomer.model.StatusModel;
import com.droidclaimcustomer.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class ClaimListAdapter extends ArrayAdapter<ClaimInfoModel>{
	private Context context;
	private int id;
	private List<ClaimInfoModel> claimList;
	private SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd-MM-yyyy");
	private StatusModel statusModel;

	public ClaimListAdapter(Context context, int resource, List<ClaimInfoModel> items) {
		super(context, resource, items);
		id = resource;
		claimList = items;
		
		statusModel = new StatusModel(context);
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub

		View view = convertView;
		try {

			View rowView = null;
			if (convertView == null) {
				// create adapter layout
				view = new LinearLayout(getContext());
				String inflater = Context.LAYOUT_INFLATER_SERVICE;
				LayoutInflater vi = (LayoutInflater) getContext()
						.getSystemService(inflater);
				rowView = vi.inflate(id, (LinearLayout) view, true);
			} else {
				rowView = convertView;
			}

			// set data to the TextView of each row
			TextView claimId = (TextView) rowView
					.findViewById(R.id.claimId_textview);
			claimId.setText(claimList.get(position).getId() + "");
			
			TextView accDateView = (TextView) rowView
					.findViewById(R.id.accidentDate_textview);
			if(claimList.get(position).getAccDate().equals(null))
			{
				accDateView.setText("");
			}
			else{
				accDateView.setText(DATE_FORMAT.format(claimList.get(position).getAccDate()) + "");
			}
			
			TextView locationView = (TextView) rowView
					.findViewById(R.id.location_textview);
			locationView.setText(claimList.get(position).getAccLocation());
			
			TextView statusView = (TextView) rowView
					.findViewById(R.id.status_textview);
			statusView.setText(statusModel.getStatus(claimList.get(position).getStatus()) + "");

		} catch (Exception ex) {
			Toast.makeText(context, ex.getMessage(), Toast.LENGTH_SHORT).show();
		}

		return view;
	}
	

}
